/**
 * Created by lijing on 2016-06-22.
 */
$.validator.setDefaults({
    submitHandler: function () {
        savePub();
    }
});
$(document).ready(function () {
    validate();
    $("#channeName").click(function () {
        $("#channeName").cate({
            title: "选择渠道",
            url: G_Path.path + "/channel/json",
            param: {},
            liveSearch: false,
            "id": "channeId",
            "name": "channeName"
        });
    });
});

function savePub() {
    $.post(G_Path.path + "/channel/interface/save", $("#mainForm").serialize(), function (text) {
        var data = $.parseJSON(text);
        if (data.success) {
            if ("view" == status) {
                history.back();
            } else {
                window.close();
            }
        }
    });
}

function validate() {
    //设置默认属性
    $("#mainForm").validate({
        rules: {
            vipName: {
                required: true,
                minlength: 1
            },
            userName: {
                required: true,
                minlength: 1
            },
            userPassword: {
                required: true,
                minlength: 1
            },
        },
        messages: {
            vipName: {
                required: "请输入会员名",
                minlength: ""
            },
            userName: {
                required: "请输入用户名",
                minlength: ""
            },
            userPassword: {
                required: "请输入密码",
                minlength: ""
            },
        }
    });
}